<?
ob_start();
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();
include("common/page.php");
include("class/OrderRecord.php");
include("class/ProOrder.php");
include("class/SimpleExcel.class.php");
$atype= 'sale';// 导出文件名判断条件
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s= new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID=$_SESSION['sid'];
//如果是admin，就不要下拉
// 获取分销商
include 'getDistors.php';
if($_SESSION['dtype']==7){// 集团账号获取供应商和分销商
	$disList = getAll($GLOBALS['le'],$_SESSION['sid']);

} elseif ($_SESSION['dtype'] != 7 && $_SESSION['dtype'] != 9) {
    $disList = getRetail($GLOBALS['le']);
}

$dTypeName = '分销商';

//print_r($anames);
$pOrder=saleProOrderObject($memberID,$s,$_SESSION['sdtype']);
// admin 账号

//$v['title']="已卖出的产品";
$v['title'] ="已卖出的产品";
$v['title2']="分销订单";
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:15;
// 导出订单设置
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export"){
	$currentPage=1;
    $pageSize = 99999;
    set_time_limit(1800);
}
$_GET['endtime']   = $_GET['endtime']   ? $_GET['endtime']    : date('Y-m-d 23:59:59',$_SERVER['REQUEST_TIME']);
$_GET['begintime'] = $_GET['begintime'] ? $_GET['begintime']  : date('Y-m-d 00:00:00',$_SERVER['REQUEST_TIME']);
$r=$pOrder->_orderlist($currentPage,$pageSize);
if($_GET['csj'] == 21){
    echo "<pre>";
    print_r($r);
    echo "</pre>";
}

$fids=array();
$orderCount = $ticketCount = $allMoney = 0;// 订单统计信息

// 未验证也显示手机号账号配置文件
$showTel = include_once '/var/www/html/new/d/module/zax/saleProduct_showTel.php';
//悠游吧的员工帐号
$youyouba = array(
    0 => 'yytx009',
    1 => 'yytx010',
    2 => 'yyb0006',
    3 => 'yytx011',
    4 => 'yytx888',
    5 => 'zhangjiayi',
    6 => 'daizihan',
    7 => 'luyuan',
    8 => 'dengfengying',
    9 => 'xiaoxi',
    10 => 'liangjinglin',
    11 => 'lichangwei',
    12 => 'zhoumengke',
    13 => 'teshudingdan',
	14 => '502837',
);
$showTel = array_merge($showTel, $youyouba);

$mids = array();
if (count($r)) {
    foreach ($r as $key => $row) {
        // 直接供应商查看价格
        if ($_SESSION['dtype'] == 2) {
            $r[$key]['mainOrder']->UUtprice = $s->get_Dynamic_Price_Merge((string)$row['mainOrder']->UUpid, (string)$row['mainOrder']->UUbegintime, 1);
        }


        if ($r[$key]['mainOrder']->UUlid != 72 && !in_array($_SESSION['account'], $showTel)) {
            if ($r[$key]['mainOrder']->UUstatus != 1) {
                $r[$key]['mainOrder']->UUordertel = substr_replace((string)$r[$key]['mainOrder']->UUordertel, "****", 3, 4);
            }
        }

        $fids[] = (string)$row['mainOrder']->UUbuyid;
        if ($_SESSION['dtype'] == 2) $aid = (string)$row['mainOrder']->UUsellid;

        $r[$key]['totalPrice'] = ((string)$row['mainOrder']->UUtprice * (string)$row['mainOrder']->UUtnum);
        // 统计订单信息
        $orderCount++;
        $ticketCount += (string)$row['mainOrder']->UUtnum;
        $allMoney += ((int)$row['mainOrder']->UUtprice * (int)$row['mainOrder']->UUtnum) / 100;


        if (!isset($mids[(string)$row['mainOrder']->UUbuyid])) {
            $mids[(string)$row['mainOrder']->UUbuyid] = (string)$row['mainOrder']->UUbuyid;
        }

    }
    $mids = array_filter($mids);
    $str = "SELECT id,dname FROM pft_member where id IN(" . implode(',', $mids) . ")";
    $anames = array();
    $GLOBALS['le']->query($str);
    while ($row = $GLOBALS['le']->fetch_assoc()) {
        $anames[$row['id']] = $row['dname'];
    }
}

$tmp = $r;

$arr = array();
foreach($r as $key => $row){
	// 处理
	$concat = (string)$row['mainOrder']->UUconcat_id;
	$orderid = (string)$row['mainOrder']->UUordernum;
	if($concat==0){
		$arr[] = $r[$key];// 主订单
		continue;
	}
	if($concat!=$orderid){
		$tmp[$key] = $r[$key];
		continue;
	}

	// 主订单并且含有从订单
	foreach($tmp as $k=>$data){
		if((string)$data['mainOrder']->UUconcat_id==$orderid && (string)$data['mainOrder']->UUordernum!=$orderid){
			$r[$key]['childOrder'][] = $data;
			unset($tmp[$k]);
		}
	}
	$arr[] = $r[$key];
}
if($_GET['txt'] == -1){
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}
$r = $arr;
if ($fids && ($_SESSION['dtype'] != 2)) {
    $fids = array_filter($fids);
    $sel="select id,dname from pft_member where id in (".implode(",",$fids).")";
	$fnames=array();
	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$fnames[$row['id']]=$row['dname'];
	}
}

include("loadExcel_new.php");
echo $out_html;

// 判断订单是否为主订单  true为主订单
function isMainOrder($field){
	return ($field=='main' || $field!=0 ) ? true:false;
}
// 复票订单主订单
function echoMainOrder($obj){
	return ((String)$obj->UUconcat_id=='main') ? (String)$obj->UUordernum:(String)$obj->UUconcat_id;
}
//时间跨度大于两个月 管理员帐号 没有传任何限制条件 则不显示统计信息 ,页数也用假的
$time_mark =((strtotime($_GET['endtime']) - strtotime($_GET['begintime']))<5092000 || $_GET['txt'] || $_SESSION['sid']!=1);


$count= $time_mark ? $pOrder->orderlistTotal() : mt_rand(10000,99999);

$showTotalOrder = array(1,4,22647);


if(in_array($_SESSION['sid'],$showTotalOrder) && $time_mark){
    $count_total=$pOrder->totalOrders(2);
    $count_total = explode(',',$count_total);
}
if($_SESSION['sid']==1 && $time_mark){
    //计算没有转分销的订单,金额数量
    $disList = array();
    /*
    switch ($_GET['xtimes']) {
    	case '1':
        case '2':
            $sql = "select sum(tnum)as total_2,sum(tnum*tprice)as total_3,count(*)as total_1 from uu_ss_order where ordertime>='{$_GET['begintime']}' and ordertime<='{$_GET['endtime']}'";
            echo $sql;exit;
    		break;
    	default:
            $sql = "select sum(tnum) as total_2,sum(tnum*tprice)as total_3,count(*) as total_1 from uu_ss_order where dtime>='{$_GET['begintime']}' and dtime<='{$_GET['endtime']}'";
    		break;
    }
    $GLOBALS['le']->query($sql);
    $row=$GLOBALS['le']->fetch_assoc();
    $count_total_lastLevel[] = $row['total_1'];
    $count_total_lastLevel[] = $row['total_2'];
    $count_total_lastLevel[] = $row['total_3'];
    */
    $count_total_lastLevel=$pOrder->totalOrders_lastLevel();
	$count_total_lastLevel = explode(',',$count_total_lastLevel);
}


if($_SESSION['account']=='csj1' && $_GET['csj']==1 && $_GET['txt'] && $_GET['tjs']==='0'){
    echo '<pre>';
    print_r($r);
    echo '</pre>';
}


$arr_salerid=array(501610,501612);
$uuStatus = array(
	0=>"未使用",
	1=>"<em class='green'>已使用</em>",
	2=>"已过期",
	3=>"<em class='red'>已取消</em>",
	4=>"被替代",
	5=>"被修改",
	6=>"已撤销",
	7=>"部分使用"
);

$transFlag = true;
// 不显示分销商列
$showDtrArr = array(2223);
$showDtr = true;
if(in_array($_SESSION['sid'], $showDtrArr)){
	$showDtr = false;
}

$v['from'] = 'sale';
include("tpl/orderlist_dev_new.html");

include("common/footer.html");
?>